package com.giaothong.http;

import org.json.JSONObject;

import android.content.Context;

import com.giaothong.config.Define;
import com.giaothong.config.ServerUrl;
import com.giaothong.http.core.HttpAsyncCallback;
import com.giaothong.http.core.HttpConnectionId;
import com.giaothong.http.core.NewHttpConnectionAsync;
import com.giaothong.utils.ALog;
import com.google.android.maps.GeoPoint;

public class HttpGetDirectionRequest extends NewHttpConnectionAsync {

	public HttpGetDirectionRequest(Context context, HttpAsyncCallback<JSONObject> callback) {
		super(context, HttpConnectionId.GET_DIRECTION, callback);
	}

	/**
	 * Call this func to request to server
	 * 
	 * @param pram1
	 * @param param2
	 */
	public void request(GeoPoint startLocation, GeoPoint endLocation, String method, boolean sensor) {
		// Create json object with data
		rootObj = new JSONObject();

		addParam("origin", (double) (startLocation.getLatitudeE6()) / 1000000 + "," + (double) startLocation.getLongitudeE6() / 1000000);
		addParam("destination", (double) endLocation.getLatitudeE6() / 1000000 + "," + (double) endLocation.getLongitudeE6() / 1000000);
		addParam("sensor", "" + sensor);
		addParam("mode", method);
		addParam("language", Define.LANGUAGE);
		

		// executable request
		ALog.i("Requests", ServerUrl.GET_DIRECTION_URL + "___" + rootObj.toString());
		this.execute(ServerUrl.GET_DIRECTION_URL);
	}

}